Dynomotion

Group: DynoMotion Message: 12292 From: Hardy Family Date: 9/21/2015
Subject: Finding out which threads are running
I am trying to implement a version of MutexLock() which supports a timeout.  A difficulty arises in the case of a thread being killed while it has the lock (I am using TestAndSet() as the serialization primitive).  MutexLock() takes care of this, but I can't work out how to do it manually with TAS.

The idea is to have a continuous check in our supervisor main loop for the lock being held by a thread which is no longer running.  Trouble is, there is no documented function to return a bitmap etc. of currently running threads, or a function to check if thread N is currently active.

Any ideas?

What we are really hoping to achieve is serialization of the PC comms "channel" so that multiple threads can talk to the PC application without treading on each other.  We have strict timeouts of 0.7 sec for most command+response, to make sure that all threads get a fair shake.  If the PC takes longer than this, it probably isn't there so we want to move on.

Regards,
SJH

Group: DynoMotion Message: 12293 From: Tom Kerekes Date: 9/21/2015
Subject: Re: Finding out which threads are running
Hi SJH,

Can't say I fully understand, but there is an undocumented bitmap as:

extern volatile int ThreadActive;  // one bit for each thread   

We will include this in KMotionDef.h in the next Version.

HTH
Regards
TK

Group: DynoMotion Message: 12294 From: Hardy Family Date: 9/21/2015
Subject: Re: Finding out which threads are running
Looks good, I'll give it a try.

Basically, the persist var 100 is a kind of bottleneck in that it only allows one transaction to be in progress at a time, so its use needs to be serialized among different threads.  For our application, it is important not to block the supervisor for too long waiting to access PC comms, since it is responsible for managing a hardware watchdog and other time-sensitive stuff like handling Estop.

Actually, I have toyed with the idea of using all 8 persist vars (100-107) to make an 8-channel PC comms link, one for each thread, but that's probably overkill for now, and not compatible with KMotionCNC etc.  The idea is to pack more info in each persist var: 8 bit field for the command code, and 16-bit offset into gather buffer used for parameter passing and results.  Grabbing data from the gather buffer is faster than getting individual persist vars.

Regards,
SJH


On Mon, Sep 21, 2015 at 12:20 PM, Tom Kerekes tk@... [DynoMotion] <DynoMotion@yahoogroups.com> wrote:
 

Hi SJH,

Can't say I fully understand, but there is an undocumented bitmap as:

extern volatile int ThreadActive;  // one bit for each thread   

We will include this in KMotionDef.h in the next Version.

HTH
Regards
TK